package com.shop.servlet;

import com.shop.bean.User;
import com.shop.dao.UserDao;
import com.shop.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "QueryServlet" ,urlPatterns = "/jun.do")
public class QueryServlet extends HttpServlet {
    UserDao userDao = new UserDaoImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password=request.getParameter("password");
        User user = userDao.queryUserByUsername(username);
        if (user!=null){
            if (password.equals(user.getPassword())){
                response.sendRedirect("http://localhost:8080/pages/user/login_success.html");
            }else {
                response.sendRedirect("http://localhost:8080/pages/user/login.html");
            }
        }else{
            response.sendRedirect("http://localhost:8080/pages/user/login.html");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
